<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	//表格动态Id
	request.setAttribute("sn_id", (int) (Math.random() * 100000));
	//func 用来每页显示条数修改时,触发方法;
	request.setAttribute("func", "" + request.getParameter("func"));
	//为表格下方显示工具设定值,三个参数(当前页,总页数,总条数)
	request.setAttribute("setValue",
			"" + request.getParameter("setValue"));
	//获取表格下方显示工具值,4个参数(表格动态Id,当前页,总页数,总条数,每页面条数)
	request.setAttribute("getValue",
			"" + request.getParameter("getValue"));
	//获取DHTMLX表格对象
	request.setAttribute("getGrid",
			"" + request.getParameter("getGrid"));
	//传为列的编号,返回对应列的值	 ,获取选中列返回的js list对象
	request.setAttribute("getGridSelectValues",
			"" + request.getParameter("getGridSelectValues"));
	//是否开启分页功能,如果不开启,表格最大查询999999条;
	pageContext.setAttribute("isPaging",
			"" + request.getParameter("isPaging"));
	//是否开启多选功能;
	pageContext.setAttribute("isCheck",
			"" + request.getParameter("isCheck"));
	//用户sessionId
	request.setAttribute("sessionId", "" + request.getSession().getId());
%>
<script type="text/javascript">
var mygrid_${sn_id};
var mydata_${sn_id}=new Date().getTime();
function pageStart_${sn_id}(){
	var CurrentPageNum_=$("#CurrentPageNum_${sn_id}").text()-0;
	var AllPageNum_=$("#AllPageNum_${sn_id}").text()-0;
	if(CurrentPageNum_>1){
		$("#CurrentPageNum_${sn_id}").text(1);
		loadGridXml_${sn_id}();
	}
}
function pageUp_${sn_id}(){
	
	var CurrentPageNum_=$("#CurrentPageNum_${sn_id}").text()-0;
	var AllPageNum_=$("#AllPageNum_${sn_id}").text()-0;
	if( CurrentPageNum_>1){
		$("#CurrentPageNum_${sn_id}").text(CurrentPageNum_-1);
		loadGridXml_${sn_id}();
	}
}
function pageDown_${sn_id}(){
	var CurrentPageNum_=$("#CurrentPageNum_${sn_id}").text()-0;
	var AllPageNum_=$("#AllPageNum_${sn_id}").text()-0;
	if(CurrentPageNum_<AllPageNum_){
		$("#CurrentPageNum_${sn_id}").text(CurrentPageNum_+1);
		loadGridXml_${sn_id}();
	}
}
function pageEnd_${sn_id}(){
	var CurrentPageNum_=$("#CurrentPageNum_${sn_id}").text()-0;
	var AllPageNum_=$("#AllPageNum_${sn_id}").text()-0;
	if(CurrentPageNum_<AllPageNum_){
		$("#CurrentPageNum_${sn_id}").text(AllPageNum_);
		loadGridXml_${sn_id}();
	}
}
function pageTo_${sn_id}(){
	var CurrentPageNum_=$("#CurrentPageNum_${sn_id}").text()-0;
	var AllPageNum_=$("#AllPageNum_${sn_id}").text()-0;
	var pageTo_=$("#pageTo_${sn_id}").val();
	if(pageTo_<1||pageTo_>AllPageNum_){
		 SN.alert.info("页码不正确",function (obj){});
		return ;
	}else{
		$("#CurrentPageNum_${sn_id}").text(pageTo_);
		loadGridXml_${sn_id}();
	}
}
function pageChange_${sn_id}(){
	$("#CurrentPageNum_${sn_id}").text(1);
	var PageSize_=$("#pageSize_${sn_id}").val();
	callback_${sn_id}();
}
function callback_${sn_id}(){
	var CurrentPageNum_=$("#CurrentPageNum_${sn_id}").text()-0;
	var PageSize_=$("#pageSize_${sn_id}").val();
	${func}();
}
function ${setValue}(CurrentPageNum,AllPageNum,allCount,func){
	$("#CurrentPageNum_${sn_id}").text(CurrentPageNum);
	$("#AllPageNum_${sn_id}").text(AllPageNum);
	$("#AllCount_${sn_id}").text(allCount);
	loadGridXml_${sn_id}(func);
}
/**
 * 获取时,为新的数据ID,默认为
 */
function ${getValue}(isFixDataId){
	var o1=$("#CurrentPageNum_${sn_id}").text();
	var o2=$("#AllPageNum_${sn_id}").text();
	var o3=$("#AllCount_${sn_id}").text();
	var PageSize_=$("#pageSize_${sn_id}").val();
	if(isFixDataId){
		
	}else{
		mydata_${sn_id}=new Date().getTime();
	}
	return {"gridId_":mydata_${sn_id},"CurrentPageNum_":o1,"AllPageNum_":o2,"AllCount_":o3,"PageSize_":PageSize_};
}
function pageCheckAll_${sn_id}(){
	mygrid_${sn_id}.checkAll(true);
}
function pageUnCheckAll_${sn_id}(){
	mygrid_${sn_id}.checkAll(false);
}
</script>
<script type="text/javascript">
function initGrid_${sn_id}(){
	var myLayout = new dhtmlXLayoutObject("gridbox_${sn_id}", "1C");
	myLayout.cells("a").setText("查询结果");
	myLayout.cells("a").hideHeader();
	mygrid_${sn_id} = myLayout.cells("a").attachGrid();
	mygrid_${sn_id}.enableAlterCss("even", "uneven");
	mygrid_${sn_id}.setImagePath("scripts/dhtmlx/codebase/imgs/dhxgrid_" + skin + "/");
	mygrid_${sn_id}.enableEditEvents(false, false, true);
	mygrid_${sn_id}.init();
	mygrid_${sn_id}.attachEvent("onRowDblClicked",function(rowId,cellIndex){
		var v=mygrid_${sn_id}.cells(rowId, 0).getValue();
		if(v==1){
			mygrid_${sn_id}.cells(rowId, 0).setValue(0);
		}else{
			mygrid_${sn_id}.cells(rowId, 0).setValue(1);
		}
	});
}
function ${getGrid}(){
	return mygrid_${sn_id};
}
function ${getGridSelectValues}(obj){
	var v=new Array();
	var i=0;
	mygrid_${sn_id}.forEachRow(function(id) {
		if (mygrid_${sn_id}.cells(id, 0).getValue() == 1) {
			v[i++]=mygrid_${sn_id}.cells(id, obj).getValue();
		}
	});
	return v;
}
/**
 *加载GridXml到myGrid
 */
function loadGridXml_${sn_id}(func) {
	$("#page_message").text("数据加载中...");
	var currentPageNum=$("#CurrentPageNum_${sn_id}").text();
	mygrid_${sn_id}.clearAndLoad("${basePath}resourse/${sessionId}_grid_"+mydata_${sn_id}+"_" + currentPageNum + ".xml", function() {
		$("#page_message").text("数据加载完成");
		if(func){
		func.call();
		}
	});
}
$(function (){
	initGrid_${sn_id}();
});
</script>
<table style="width:98%;height:100%;margin-left:auto;margin-right:auto;" border="0">
	<tr class="footerCont" style="height: 5px">
		<td></td>
	</tr>
	<tr style="height: auto;">
		<td style="width:98%;height:100%;">
			<div id="gridbox_${sn_id}" style="width:100%; height:100%; background-color:white;margin:auto"></div>
		</td>
	</tr>
	<tr class="footerCont" style="height: 5px">
		<td></td>
	</tr>
	<tr class="footerCont" style="height: 18px;${isPaging?'':'display:none;'}">
		<td style="width:98%;height:100%;">
			<c:if test="${isCheck != 'false' }">
				<button type="button" onclick="pageCheckAll_${sn_id}()" class="btn btn-primary" aria-label="Left Align">全选</button>
				<button type="button" onclick="pageUnCheckAll_${sn_id}()" class="btn btn-primary" aria-label="Left Align">全不选</button>
			</c:if>
			<!-- 分页 -->
			<button type="button" onclick="pageStart_${sn_id}()" class="btn btn-primary" aria-label="Left Align">
				<span class="glyphicon glyphicon-fast-backward" aria-hidden="true"></span>
			</button>
			<button type="button" onclick="pageUp_${sn_id}()" class="btn btn-primary" aria-label="Left Align">
				<span class="glyphicon glyphicon-backward" aria-hidden="true"></span>
			</button>
			&nbsp;
			<span id="CurrentPageNum_${sn_id}">1</span>
			<span>/</span>
			<span id="AllPageNum_${sn_id}">1</span>
			&nbsp;
			<button type="button" onclick="pageDown_${sn_id}()" class="btn btn-primary" aria-label="Left Align">
				<span class="glyphicon glyphicon-forward" aria-hidden="true"></span>
			</button>
			<button type="button" onclick="pageEnd_${sn_id}()" class="btn btn-primary" aria-label="Left Align">
				<span class="glyphicon glyphicon-fast-forward" aria-hidden="true"></span>
			</button>
			&nbsp;
			<span>总条数：</span>
			<span id="AllCount_${sn_id}">0</span>
			&nbsp;
			<span>每页显示条数：</span>
			<select id="pageSize_${sn_id}" onchange="pageChange_${sn_id}()">
				${isPaging?'':'<option>9999999</option>'}
				<option>15</option>
				<option>20</option>
				<option>50</option>
				<option>100</option>
			</select>
			&nbsp;
			<span>跳转至</span>
			<input id="pageTo_${sn_id}" type="text" style="width:50px" />
			<span>页</span>
			&nbsp;
			<button type="button" onclick="pageTo_${sn_id}()" class="btn btn-primary">确定</button>
			<span id="page_message_${sn_id}"></span>
		</td>
	</tr>
	<tr class="footerCont" style="height: 5px">
		<td></td>
	</tr>
</table>
